<?php

require_once 'control/common/teams/form.php';
require_once 'view/pub/teams/team.edit.php';


require_once APP_ROOT . 'view/common/layout.formview.php';
require_once APP_ROOT . 'view/common/layout.view.php';
require_once WACT_ROOT. 'view/redirecturl.inc.php';
require_once APP_ROOT . "model/common/site.php";

class TeamsSubmitPage extends PageController {

	var $form;
	var $view;

    function TeamsSubmitPage() {
        parent::PageController();
        $this->form =& new TeamFormController();


        if(!Session::isLogin()){
        	$this->setDefaultView( new RedirectUrlView($redirect_url='http://'.$_SERVER['HTTP_HOST'].'/myprofile/index.htm'));
        	return;
        }

        $user=&Session::getUserArray();
        if($user['level']==2) {
        	$admin=true;
        	$staff=true;
        }else {
        	$admin=false;
        	if(isset($user['staff'])&&$user['staff']==1)
        		$staff=true;
        	else $staff=false;
        }

        $this->form->setUserType($admin,$staff);
        $this->addChild('TeamForm', $this->form);
        $this->setDefaultChild('TeamForm');
 
        $mytemplate1 = 'pub/teams/submit.html';
       

        // pass form controller as a parameter
        //$this->view =& new Handle('PlayerEditView', array('/common/articles/article.edit.page.html',$this->form));
        $this->view =& new TeamSubmitView($mytemplate1, $this->form);
        $this->form->setView($this->view);

        $this->setDefaultView($this->view);

        $this->addView('success', WACT_DEFAULT_VIEW);
        $this->addView('notfound', WACT_DEFAULT_VIEW);
        $this->addView('delete', new Handle('RedirectView', array('/delete')));

        $redirect_url=HOST.'/myprofile/message.htm?type=';
        $session_url="";
    	if(defined('SID')&&(!isset($_COOKIE[session_name()])))
    		$session_url.=SID;
    	$redirect_create=$redirect_url.'1&'.$session_url;
    	$redirect_save=$redirect_url."2&".$session_url;
    	$redirect_clean='http://'.$_SERVER['HTTP_HOST'].'/teams/submit.htm?'.$session_url;
    	$redirect_index='http://'.$_SERVER['HTTP_HOST'].'/teams/index.htm?'.$session_url;

    	$this->addView('index', new RedirectUrlView($redirect_index));
		$this->addView('createOK', new RedirectUrlView($redirect_create));
        $this->addView('saveOK', new RedirectUrlView($redirect_save));
        $this->addView('cleanOK', new RedirectUrlView($redirect_clean));
        $this->addView('this', WACT_DEFAULT_VIEW);
    }
}

?>
